<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page contentType="text/html; charset=UTF-8" session="false"  deferredSyntaxAllowedAsLiteral="true"%>
<strong><%@ taglib prefix="c"
                   uri="http://java.sun.com/jsp/jstl/core" %></strong>
<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>字典新增</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="/xAdmin/css/font.css">
    <link rel="stylesheet" href="/xAdmin/css/xadmin.css">
    <link rel="stylesheet" href="/xAdmin/lib/layui/css/layui.css"  media="all">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="/xAdmin/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/xAdmin/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form method="post" class="layui-form">
            <input type="hidden" value="${tStyle.id}" id="styleId">
            <input type="hidden" value="${level}" id="dd">
            <c:if test="${not empty styleList}">
                <input type="hidden" id="level" value="1">
                <div class="layui-form-item">
                    <label class="layui-form-label">上级</label>
                    <div class="layui-input-block" style="width: 100px">
                        <select name="fid" id="fid"  lay-verify="" lay-filter="style">
                            <c:forEach  items="${styleList}" var="list">
                                <option value="${list.id}" title="${list.stylename  }" <c:if test="${tStyle.fid==list.id}"> selected </c:if>
                                >${list.styledesc}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
            </c:if>

            <c:if test="${empty styleList}">
                <div class="layui-form-item">
                    <label for="stylename" class="layui-form-label">
                        字段名称
                    </label>
                    <div class="layui-input-inline">
                        <input type="hidden" id="fid" value="0">
                        <input type="hidden" id="level" value="0">
                        <input type="text" id="stylename" name="stylename" required="" lay-verify="required"
                               autocomplete="off" class="layui-input" value="${tStyle.stylename}">
                    </div>
                </div>
            </c:if>

            <div class="layui-form-item">
                <label for="stylevalue" class="layui-form-label">
                    值
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="stylevalue" name="stylevalue" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" value="${tStyle.stylevalue}">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="styledesc" class="layui-form-label">
                    说明
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="styledesc" name="styledesc" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" value="${tStyle.styledesc}">
                </div>
            </div>
            <c:if test="${tStyle.level==2||level==2}">
                <div class="layui-form-item">
                    <input type="hidden" id="level" value="2">
                    <label for="picPath" class="layui-form-label">
                        图片地址
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="picPath" name="picPath" required="" lay-verify="required"
                               autocomplete="off" class="layui-input" value="${tStyle.picPath}">
                    </div>
                </div>
            </c:if>

            <div class="layui-form-item">
                <label  class="layui-form-label">
                </label>
                <button type="button" class="layui-btn" lay-filter="add"  onclick="Issubmit()">
                    增加
                </button>
            </div>

        </form>
    </div>
</div>
<script>
    layui.use('form', function(){
        var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
        // form.render('select');
    });


    function Issubmit(){
        var fid = null;
        var stylename =null ;
        if($('#fid').is("input")){
            fid =$('#fid').val();
            stylename =  $('#stylename').val();
        } else if($('#fid').is("select")){
            fid =$('#fid option:selected').val();
            stylename = $('#fid option:selected').attr("title");
            console.log(fid);
            console.log(stylename);
        }

        var stylevalue =  $('#stylevalue').val();
        var styleId= $('#styleId').val();
        var styledesc =  $('#styledesc').val();
        var level =  $('#level').val();
        var picPath = $('#picPath').val();
        var date =null;
        if(styleId==null||styleId==""){
            data = {
                fid:fid,
                stylename:stylename,
                stylevalue:stylevalue,
                styledesc:styledesc,
                picPath:picPath,
                level:level
            };
        }else{
            data = {
                id:styleId,
                fid:fid,
                stylename:stylename,
                stylevalue:stylevalue,
                styledesc:styledesc,
                picPath:picPath,
                level:level

            };
        }

        $.ajax({
            url:"/tBizStyle/saveOrUpdate",
            type:'post',
            dataType:'text',
            contentType: 'application/json',
            data:JSON.stringify(data),
            timeout:2000,
            success:function(data){
                var layer = parent.layui.layer;
                if(data == 'success')
                    layer.msg('操作成功!',{icon:1,time:1000});
                else
                    layer.msg('操作失败!',{icon:1,time:1000});
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
            },
            error:function () {
                var layer = parent.layui.layer;
                layer.msg("操作失败",{icon:1,time:1000});
            }
        })
    }

</script>

</body>

</html>
